<template>
	<view class="container">
	
		<uni-notice-bar text="兑换地址 : 浙江省宁波市北仑区柴桥服务区预录点" />
		
		<scroll-view class="pointsList" refresher-enabled :refresher-triggered="isRefreshing"  @refresherrefresh="onRefresh" @scrolltolower="onLoadMore" scroll-y>
		    <view class="points-item" v-for="(item, index) in pointsList" :key="index">

		      <view class="points-box">
				  <view class="points-img">
				  	<image :src="'http://115.120.208.220:8000/prod-api' + item.photo" style="width: 100%; height: 200rpx;"></image>
				  </view>
				  <view class="points-name">
					  <text>{{ item.remark }}</text>  
				  </view>
			
				  <view class="points-state" style="color: red;">
					 所需积分： {{ item.points }}
				  </view>
				 
		      </view>
		      
		    </view>
		  </scroll-view>

	</view>
</template>

<script>
import { getPoints } from '@/api/system/points'

export default {
	
	
	data() {
		return {
			isRefreshing: false,
            page: '1',
			pageSize:'10',
			pointsList: [],
			total: 0 // 添加总数据数
			    
		}
	},

	// 页面加载时触发（接收参数）
	onLoad(options) {
		this.getList(); // 调用初始化方法
	},
	methods: {
		onRefresh() {
		  uni.showLoading({ title: '刷新中' });
		  this.isRefreshing = true;
		  this.page = 1;
		  this.getList()
			.catch(() => {})
			.finally(() => {
			  this.isRefreshing = false;
			  uni.hideLoading();
			});
		},
		onLoadMore() {
		  // 判断是否还有更多数据可以加载
		  if (this.pointsList.length < this.total) {
		    this.page++;
		    this.getList();
		  } else {
		    uni.showToast({
		      title: '没有更多数据了',
		      icon: 'none'
		    });
		  }
		},
		
		// 修改后的 getList 方法
		getList() {
		  return getPoints({ pageNum: this.page, pageSize: this.pageSize })
		    .then((response) => {
		      // 如果是第一页，重置列表
		      if (this.page === 1) {
		        this.pointsList = [];
		      }
		      // 保存总数据数
		      this.total = response.total;
		      // 拼接新数据
		      this.pointsList = this.pointsList.concat(response.rows);
		      
		      // 如果已经加载完所有数据，提示用户
		      if (this.pointsList.length >= response.total) {
		        uni.showToast({
		          title: '已加载全部数据',
		          icon: 'none'
		        });
		      }
		    });
		},
	
		
		pointsStatus(item,index){
			item.status = parseInt(index) + 1;
			
			updatepoints(item).then(response => {
				if(response.code==200){
					uni.showToast({ icon: 'success', title: '操作成功',duration:3000 });
					setTimeout(()=>{
						uni.navigateBack();
					},2000)
				}else{
					uni.showToast({
					  title:response.msg,
					  icon:'none'
					})
				}
			}).finally(() => {
				uni.hideLoading();
			});

		}
	
		
	}
}
</script>

<style scoped lang="scss">
.fl{
    float: left;
}
.fr{
    float: right;
}
.clear{
	clear: both;
}
/* 保持原有样式不变 */
.container {
   
   display: flex;
   flex-direction: column; /* 垂直排列子元素 */
   height: 100vh; /* 关键：容器高度充满视窗 */
   background-color: #f2f2f2;
}

.pointsNav{
   background-color: #ffffff;
}
.pointsList {
   padding: 0 20rpx;
   width: 100%;
   flex: 1; /* 关键：占据剩余空间 */
   overflow-y: auto; /* 确保滚动生效 */
   
   
   
   .points-item {
	  width: 48%;
      margin-top: 20rpx;
      padding: 30rpx;
      border-radius: 20rpx;
      box-shadow: 0 2px 16rpx rgba(0, 0, 0, 0.1);
      background-color: #ffffff;
	  float: left;
   }
   
   .points-item:nth-child(2n) {
   	  float: right;
   }
   
   
   .points-top {
   	  width: 100%;
   	  height: 60rpx;
   	  line-height: 60rpx;
   	  border-bottom: 1rpx solid #e6e6e6;
   }
   
   .points-box {
      margin-bottom: 10rpx;
      padding-top: 10rpx;
     
     .points-name{
		 margin-top: 20rpx;
   	     font-size: 30rpx;
   	     font-weight: bold;
     }
	 .points-details{
		 margin-top: 20rpx;
		 color: #777777;
		 font-size: 26rpx;
	 }
   }
}


.weui-btn_large {
	width: 100%;
	background: #007AFF;
}
.weui-btn_primary:not(.weui-btn_disabled):visited{
  color:#FFFFFF;
}
.weui-btn_primary:not(.weui-btn_disabled):active{
  color:#FFFFFF;
  background-color:#1975da;
}

</style>